package com.taxsystem.yehao.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.taxsystem.yehao.jsonParser.HallWaitDetailJsonParser;
import com.taxsystem.yehao.jsonParser.HallWaitListJsonParser;
import com.taxsystem.yehao.tool.UrlHost;
import com.main.taxsystem.R;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class HallWaitDetailActivity extends BaseListActivity {

	private String branchId;
	private TextView onlineCounterSum;
	private TextView waitSum;
	private int onlineCounter_sum;
	private int wait_sum;
	private  Handler hdlr =new Handler(){
		@Override
		public void handleMessage(Message msg){
		super.handleMessage(msg);
		switch (msg.what) {
		case 0:onlineCounterSum.setText(onlineCounter_sum+"");waitSum.setText(wait_sum+"");break;
		}
		
		}
		};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.hall_wait_detail);
		lv = (ListView)findViewById(R.id.hall_wait_detail_list_view);
		progressBar = (ProgressBar) findViewById(R.id.hall_wait_detail_list_progressBar);
		branchId = getIntent().getStringExtra("branchId");
		onlineCounterSum = (TextView)findViewById(R.id.onlineCounter_sum);
		waitSum = (TextView)findViewById(R.id.waitingCount_sum);
		new Thread() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				HallWaitDetailActivity.this.setProcessBarVisible(true);
				simpleAdapter = new SimpleAdapter(HallWaitDetailActivity.this, getData(branchId), R.layout.hall_wait_detail_list_item,
						new String[] {"ticketItemId","ticketItemName","onlineCounter","waitingCount"},
						new int[] {R.id.ticketItemId,R.id.ticketItemName,R.id.onlineCounter,R.id.waitingCount});
				HallWaitDetailActivity.this.setProcessBarVisible(false);
				HallWaitDetailActivity.this.setListAdapter();
				setAddSum();
			}
			
		}.start();
		lv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View view, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				
			}
		});
	}
	
	private List<HashMap<String,Object> > getData(String branchId) {
		Map params = new HashMap<String,String>();
		params.put("branchId", branchId);
		List <HashMap<String,Object>> list = HallWaitDetailJsonParser.parse(UrlHost.host+"/app/hallinfo/waitinfo",params);
		onlineCounter_sum=0;
		wait_sum=0;
		for(HashMap<String,Object> map:list) {
			onlineCounter_sum+=Integer.parseInt(map.get("onlineCounter").toString());
			wait_sum+=Integer.parseInt(map.get("waitingCount").toString());
		}
		return list;
	}
	public void setAddSum() {
		hdlr.sendEmptyMessage(0);
	}
}
